Page({
    data: {
        value : '' ,
        id : '' ,
        type : 0 ,
        items: [
            {value: 'pass', name: '评估通过，适合参加该项目'},
            {value: 'unpass', name: '评估未通过，不适合参加该项目'},
        ],
        xSelectedKey: -1 
    },

    onLoad: function (opt) {
        console.log(opt)
        this.setData({
            id : opt.id ,
            type : opt.type
        })
    },

    xInput: function (e) {
        let that = this
        let value = e.detail.value
        that.setData({
            value: value
        })
    },

    xSub: function () {
        let that = this
        let value = that.data.value
        let id = that.data.id
        if (value == '') {
            wx.showToast({
                title : '请输入后提交',
                icon : 'none'
            })
            return false
        } else {
            let _objData = {
                _id: id, 
                summary: [
                    {
                        type : 1 ,
                        content : value
                    }
                ]
            }
            wx.cloud.callFunction({
                name: 'digital_therapy',
                data: {
                    action: "add_interview_summary",
                    objData: _objData
                }
            }).then(res => {
                console.log("返回数据:", res)
                wx.showToast({
                    title: '提交成功',
                    icon: 'none',
                    success : () => {
                        setTimeout( () => {
                            wx.navigateBack({
                                delta: 1,
                            })
                        } , 1000)
                    }
                })
            })
        }
    },

    xErrorBack : function () {
        let that = this
        let id = that.data.id
        wx.cloud.callFunction({
            name: 'digital_therapy',
            data: {
                action: "is_audit_fail",
                _id: id
            }
        }).then(res => {
            wx.showToast({
                title: '正在为您跳转',
                icon: 'none',
                success : () => {
                    setTimeout( () => {
                        wx.navigateBack({
                            delta: -1,
                        })
                    } , 1000)
                }
            })
        })
    },

    xSelected: function (e) {
        let that = this
        let key = e.currentTarget.dataset.key
        that.setData({
            xSelectedKey : key
        })
    },

    xEnd: function () {
        let that = this
        let xSelectedKey = that.data.xSelectedKey
        console.log(xSelectedKey)
        let xType = that.data.type
        console.log(xType)
        if(xType == 1){
            if(xSelectedKey === 0){
                that.xSub()
            }else{
                that.xErrorBack()
            }
        }else{
            that.xSub()
        }
    }
})